package com.fenghongzhang.day003;

import android.database.sqlite.SQLiteDatabase;

import com.fenghongzhang.day003.db.DaoMaster;
import com.fenghongzhang.day003.db.DaoSession;

//单例
public class DaoManger {

    private DaoSession daoSession;
    private static DaoManger daoManger;
    private DaoManger(){
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(App.context, "user.db");
        SQLiteDatabase writableDatabase = devOpenHelper.getWritableDatabase();//
        //更新的方法
//        devOpenHelper.onUpgrade(writableDatabase,1,2);
        //所有数据都清空
        DaoMaster daoMaster = new DaoMaster(writableDatabase);
        daoSession = daoMaster.newSession();
    }
    public static DaoManger getInstance(){
        if(daoManger == null){
            synchronized (DaoManger.class){
                if(daoManger == null){
                    daoManger = new DaoManger();
                }
            }
        }
        return daoManger;
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }
}
